<template>
  <div class="app-container">
    <el-table
      v-loading="listLoading"
      style="margin-top: 20px"
      :data="list"
      size="mini"
      element-loading-text="Loading"
      border
      fit
      highlight-current-row
    >
      <el-table-column align="center" label="ID" width="95">
        <template slot-scope="scope" align="center">
          {{ scope.row.id }}
        </template>
      </el-table-column>
      <el-table-column label="反馈选项" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click.prevent="showList(scope.row.choice)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="反馈意见" align="center">
        <template slot-scope="scope">
          {{ scope.row.advice }}
        </template>
      </el-table-column>
      <el-table-column label="反馈图片" align="center">
        <template slot-scope="scope">
          <el-button type="text" size="mini" @click.prevent="showImg(scope.row.images)">查看</el-button>
        </template>
      </el-table-column>
      <el-table-column label="反馈时间" align="center">
        <template slot-scope="scope">
          {{ scope.row.time }}
        </template>
      </el-table-column>
    </el-table>
    <el-pagination
      style="margin-top: 20px"
      :current-page.sync="page.current"
      :page-sizes="[10,20,50,100, 200, 300, 400]"
      :page-size="page.size"
      layout="total,sizes, prev, pager, next"
      :total="page.total"
      @size-change="handleSizeChange"
      @current-change="handleCurrentChange"
    />
    <el-dialog
      title="反馈图片"
      :close-on-click-modal="false"
      :visible.sync="imageDialogVisible"
      center
    >
      <span>
        <el-carousel :interval="5000" arrow="always">
          <el-carousel-item v-for="item in dialogImg" :key="item">
            <el-image :src="item" :fit="'fill'" style="width: 100%; height: 100%">
              <div slot="placeholder" class="image-slot">
                加载中<span class="dot">...</span>
              </div>
              <div slot="error" class="image-slot">
                <i class="el-icon-picture-outline" />
              </div>
            </el-image>
          </el-carousel-item>
        </el-carousel>
      </span>
    </el-dialog>
    <el-dialog
      title="反馈选项"
      :close-on-click-modal="false"
      :visible.sync="listDialogVisible"
      center
    >
      <span>
        <ul>
          <li v-for="(item,index) in checkBoxList" :key="index" class="text item">{{ item }}</li>
        </ul>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import { feedbackRecords } from '@/api/feedback'

export default {
  filters: {
    statusFilter(status) {
      const statusMap = {
        published: 'success',
        draft: 'gray',
        deleted: 'danger'
      }
      return statusMap[status]
    }
  },
  data() {
    return {
      list: null,
      listLoading: true,
      imageDialogVisible: false,
      listDialogVisible: false,
      dialogImg: [],
      checkBoxList: [],
      page: {
        size: 20,
        current: 1,
        total: 1
      }
    }
  },
  created() {
    this.fetchData()
  },
  methods: {
    fetchData() {
      this.listLoading = true
      feedbackRecords(this.page).then(response => {
        this.list = response.body
        this.listLoading = false
        this.page.total = response.totalCount
      })
    },
    tagNameValidator(val) {
      if (val !== '') {
        return true
      } else {
        return '请输入标签名称'
      }
    },
    showImg(imgs) {
      this.$set(this, 'dialogImg', imgs)
      this.imageDialogVisible = true
    },
    showList(checkboxs) {
      this.$set(this, 'checkBoxList', checkboxs)
      this.listDialogVisible = true
    },
    handleSizeChange(val) {
      this.page.size = val
      this.fetchData()
    },
    handleCurrentChange(val) {
      this.page.current = val
      this.fetchData()
    }
  }
}
</script>
